<?php
session_start();
ob_start();
include("../function.php");
condb();
$med=mysql_fetch_assoc(mysql_query("select * from medic where med_id='$_GET[med_id]'"));
?>
<meta charset="utf-8" />
<center><h2>ใบเสร็จรับเงิน</h2></center>
<br />
<table width="700" align="center" border="1" bordercolor="#000000">
	<tr>
    	<th>ลำดับที่</th>
        <th width="200">รายการ</th>
        <th>ราคาต่อหน่วย</th>
        <th>จำนวน</th>
        <th>ราคาสุทธิ</th>
    </tr>
    <tr>
    	<td align="center">1</td>
        <td align="left">ค่ารักษา(<?php echo $med['med_name'];?>)</td>
        <td align="right"><?php echo number_format($med['med_price'],2);?></td>
        <td align="right">1.00</td>
        <td align="right"><?php echo number_format($med['med_price'],2);?></td>
    </tr>
    <?php
  	$res=mysql_query("select * from medicines where med_id='$_GET[med_id]'");
  	$i=1;
	while($mdc=mysql_fetch_assoc($res)){
		++$i;
		$med=mysql_fetch_assoc(mysql_query("select * from medic where med_id='$_GET[med_id]'"));
		$pmc=mysql_fetch_assoc(mysql_query("select * from pharmacy where pmc_id='$mdc[pmc_id]'"));
		$amount+=$pmc['pmc_price']*$mdc['amount'];
  	?>
    <tr>
    	<td align="center"><?php echo $i;?></td>
        <td align="left"><?php echo $pmc['pmc_name'];?></td>
        <td align="right"><?php echo number_format($pmc['pmc_price'],2);?></td>
        <td align="right"><?php echo number_format($mdc['amount'],2);?></td>
        <td align="right"><?php echo number_format($pmc['pmc_price']*$mdc['amount'],2);?></td>
    </tr>
    <?php
	}
	?>
    <tr>
    	<th align="center" colspan="4">รวมทั้งสิ้น</th>
        <td align="right"><?php echo number_format($amount+$med['med_price'],2);?></td>
    </tr>
</table>
<script>window.print();</script>